﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class UI拖拽 : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IPointerEnterHandler, IPointerExitHandler, IPointerDownHandler
{
    Vector2 位置偏移;
    //拖拽开始
    public void OnBeginDrag(PointerEventData eventData)
    {
        //拖拽开始
        位置偏移 = eventData.position - new Vector2(transform.position.x, transform.position.y);
        拖拽开始(eventData);
    }
    //拖拽时
    public void OnDrag(PointerEventData eventData)
    {
        //拖拽进行中
        transform.position = eventData.position - 位置偏移;
        拖拽进行中(eventData);
    }
    //停止拖拽
    public void OnEndDrag(PointerEventData eventData)
    {
        停止拖拽(eventData);
    }
    //当鼠标移动到此UI
    public void OnPointerEnter(PointerEventData eventData)
    {
        当鼠标移到UI(eventData);
    }
    //当鼠标移除UI
    public void OnPointerExit(PointerEventData eventData)
    {
        当鼠标移出UI(eventData);
    }
    //当鼠标按下UI
    public void OnPointerDown(PointerEventData eventData)
    {
        当鼠标按下UI(eventData);
    }

    /// <summary>
    /// 当开始拖拽时调用本函数(只调用一次)
    /// </summary>
    /// <param name="信息"></param>
    public virtual void 拖拽开始(PointerEventData 信息)
    {

    }
    /// <summary>
    /// 当鼠标按住拖拽时调用本函数(不松手鼠标坐标发生变动时一直运行)
    /// </summary>
    /// <param name="信息"></param>
    public virtual void 拖拽进行中(PointerEventData 信息)
    {

    }
    /// <summary>
    /// 当停止拖拽时 调用一次
    /// </summary>
    /// <param name="信息"></param>
    public virtual void 停止拖拽(PointerEventData 信息)
    {

    }
    /// <summary>
    /// 当鼠标移动到此UI时调用一次
    /// </summary>
    /// <param name="信息"></param>
    public virtual void 当鼠标移到UI(PointerEventData 信息)
    {

    }
    /// <summary>
    /// 当鼠标移除UI时调用一次
    /// </summary>
    /// <param name="信息"></param>
    public virtual void 当鼠标移出UI(PointerEventData 信息)
    {

    }
    /// <summary>
    /// 当鼠标按下UI时调用一次
    /// </summary>
    /// <param name="信息"></param>
    public virtual void 当鼠标按下UI(PointerEventData 信息)
    {

    }

}
